import * as types from '@/store/mutation-types';

export default {
  state: {
    isShow: false,
    message: '',
    func: () => {},
  },
  mutations: {
    [types.SHOW_ALERT](state, payload) {
      state.isShow = true;
      state.message = payload.message;

      // * 如果mutation中有func参数，改变state中的func
      if (payload.func) {
        state.func = payload.func;
      }
    },
    [types.HIDE_ALERT](state) {
      state.isShow = false;
      state.message = '';
      state.func = () => {};
    },
  },
  actions: {

    // * 显示alert
    showAlert({ commit }, { message, func }) {
      commit(types.SHOW_ALERT, { message, func });
    },

    // * 隐藏alert
    hideAlert({ commit }) {
      commit(types.HIDE_ALERT);
    },
  },
};
